from widgets.scriptWidgets.ScriptWidget import ScriptWidget
from enums.WidgetType import WidgetType
from PySide6.QtWidgets import QLabel
from ..ScriptTimeInput import ScriptTimeInput


class Wait(ScriptWidget):
    def __init__(self, initType=None):
        super(Wait, self).__init__(WidgetType.WAIT)

        self.labTitle = QLabel('等待:', self)
        self.labTitle.setFixedSize(30, self.lineHeight)
        self.addWidget(self.labTitle)

        self.newLineSpaceWidth = self.labTitle.width() + self.intervalX

        self.inputTime = ScriptTimeInput(self, '时间')
        self.addWidget(self.inputTime)

        if initType == 'edit' or initType == 'create':
            self.addOperate()

    @property
    def data(self):
        return {
            "type": self.type.value,
            'time': int(self.inputTime.text),
            'enable': self.switchEnable.isChecked()
        }

    @data.setter
    def data(self, data):
        self.setData(data)
        self.inputTime.text = data['time']
